home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / laptop-mode-tools / modules / start-stop-programs < prev    next >
Text File  |  2009-10-06  |  4KB  |  126 lines

  1. #! /bin/sh
  2. #
  3. # Laptop mode tools module: start and stop programs
  4. #
  5.  
  6.  
  7. if [ x$CONTROL_START_STOP = x1 ] ; then
  8.    #
  9.    # Undo the previous state.
  10.    #
  11.    if [ -f /var/run/laptop-mode-tools/start-stop-undo-actions ] ; then
  12.     cat /var/run/laptop-mode-tools/start-stop-undo-actions | \
  13.         while read SCRIPT STARTSTOPACTION ; do
  14.             $SCRIPT $STARTSTOPACTION
  15.         done
  16.    fi
  17.  
  18.    #
  19.    # Apply the new state, if LMT is enabled.
  20.    #
  21.    if [ "$STATE" = "enabled" ]; then
  22.     # Empty undo file first. We write the actions we take
  23.     # into this file, so that we can undo them at the
  24.     # next state change. Note: we actually
  25.     # write the actions to the file in reverse order,
  26.     # so we can execute the commands easily afterwards.
  27.     echo > /var/run/laptop-mode-tools/start-stop-undo-actions 
  28.         
  29.        
  30.     if [ $ON_AC -eq 1 ] ; then
  31.         if [ "$ACTIVATE" -eq 1 ] ; then        
  32.             START_STOP_DIR_PREFIX=/etc/laptop-mode/lm-ac
  33.             START_SERVICES="$LM_AC_START"
  34.             STOP_SERVICES="$LM_AC_STOP"            
  35.         else
  36.             START_STOP_DIR_PREFIX=/etc/laptop-mode/nolm-ac
  37.             START_SERVICES="$NOLM_AC_START"
  38.             STOP_SERVICES="$NOLM_AC_STOP"            
  39.         fi
  40.     else
  41.         START_STOP_DIR_PREFIX=/etc/laptop-mode/batt
  42.         START_SERVICES="$BATT_START"
  43.         STOP_SERVICES="$BATT_STOP"
  44.     fi
  45.     START_DIR="$START_STOP_DIR_PREFIX"-start
  46.     STOP_DIR="$START_STOP_DIR_PREFIX"-stop
  47.     if [ -d "$STOP_DIR" ] ; then
  48.         for SCRIPT in "$STOP_DIR"/* ; do
  49.             if [ -e "$SCRIPT" ] ; then
  50.                 $LM_VERBOSE && echo "Stopping $SCRIPT" >> $OUTPUT
  51.                 "$SCRIPT" stop
  52.                 # Dereference any links. When people configure
  53.                 # the directories with links and then they remove
  54.                 # links while laptop mode is active, the "undo"
  55.                 # will fail if we don't dereference the links
  56.                 # before storing them.
  57.                 LINKTARGET=`readlink -f "$SCRIPT"`
  58.                 sed -i "1i $LINKTARGET start" /var/run/laptop-mode-tools/start-stop-undo-actions
  59.             fi
  60.         done
  61.     fi
  62.     if [ -d "$START_DIR" ] ; then
  63.         for SCRIPT in "$START_DIR"/* ; do
  64.             if [ -e "$SCRIPT" ] ; then
  65.                 $LM_VERBOSE && echo "Starting $SCRIPT" >> $OUTPUT
  66.                 "$SCRIPT" start
  67.                 LINKTARGET=`readlink -f "$SCRIPT"`
  68.                 sed -i "1i $LINKTARGET stop" /var/run/laptop-mode-tools/start-stop-undo-actions
  69.             fi
  70.         done
  71.     fi
  72.  
  73.  
  74.     echo "START_SERVICES = $START_SERVICES" >> $OUTPUT
  75.     echo "STOP_SERVICES = $STOP_SERVICES" >> $OUTPUT
  76.     if [ "$START_SERVICES" != "" -o "$STOP_SERVICES" != "" ] ; then
  77.         echo "Starting/stopping services" >> $OUTPUT
  78.     
  79.         # Determine how we can start/restart services.
  80.         if ( which invoke-rc.d > /dev/null ) ; then
  81.             # Debian uses invoke-rc.d
  82.             RCPROG="invoke-rc.d "
  83.             INITSCRIPT=laptop-mode
  84.         elif ( which service > /dev/null ) ; then
  85.             # RedHat uses service
  86.             RCPROG="service "
  87.             INITSCRIPT=laptop-mode
  88.         else
  89.             # Any other -- we start the init script it ourselves.
  90.  
  91.             # Try non-link directories first, then try links. This helps if one of
  92.             # the locations is linked to another, which is the case on some distros.
  93.             if [ -d /etc/rc.d/init.d -a ! -L /etc/rc.d/init.d ] ; then
  94.                 INIT_D=/etc/rc.d/init.d
  95.             elif [ -d /etc/rc.d -a ! -L /etc/rc.d -a ! -d /etc/rc.d/init.d ] ; then
  96.                 INIT_D=/etc/rc.d
  97.             elif [ -d /etc/init.d -a ! -L /etc/init.d ] ; then
  98.                 INIT_D=/etc/init.d
  99.             elif [ -d /etc/rc.d/init.d ] ; then
  100.                 INIT_D=/etc/rc.d/init.d
  101.             elif [ -d /etc/rc.d ] ; then
  102.                 INIT_D=/etc/rc.d
  103.             elif [ -d /etc/init.d ] ; then
  104.                 INIT_D=/etc/init.d
  105.             else
  106.                 $LM_VERBOSE && echo "Cannot determine location of init scripts." >> $OUTPUT
  107.                 exit 1
  108.             fi
  109.  
  110.             RCPROG="$INIT_D/"
  111.         fi
  112.  
  113.         for SERVICE in $STOP_SERVICES ; do
  114.             $LM_VERBOSE && echo "Stopping service $SERVICE." >> $OUTPUT
  115.             $RCPROG$SERVICE stop
  116.             sed -i "1i $RCPROG$SERVICE start" /var/run/laptop-mode-tools/start-stop-undo-actions
  117.         done
  118.         for SERVICE in $START_SERVICES ; do
  119.             $LM_VERBOSE && echo "Starting service $SERVICE." >> $OUTPUT
  120.             $RCPROG$SERVICE start
  121.             sed -i "1i $RCPROG$SERVICE stop" /var/run/laptop-mode-tools/start-stop-undo-actions
  122.         done
  123.     fi
  124.    fi
  125. fi
  126.